import { ref } from 'vue';
import { defineStore } from 'pinia'
import {getDicts} from '@/common/request/api'
import type {DictsItem} from '@/common/request/api'



export const useOrder = defineStore('order', () => {
	const orderStatusText = ref<DictsItem[]>([])
	let isGetRefundStatus = true
	
	const getOrderStatusText = async () => {
		const res = await getDicts('order_receiving_status')
		orderStatusText.value = res.data
	}
	const orderRefundStatusText = ref<DictsItem[]>([])
	const getOrderRefundStatusText = async () => {
		const res = await getDicts('order_refund_status')
		orderRefundStatusText.value = res.data
	}
	const orderCancelText = ref<DictsItem[]>([])
	const getOrderCancelText = async () => {
		const res = await getDicts('h_order_cancel')
		orderCancelText.value = res.data
	}
	const reservationOrderStatusText = ref<DictsItem[]>([])
	const getReservationOrderStatusText = async () => {
		if(!isGetRefundStatus) return 
		const res = await getDicts('appointment_order_state')
		isGetRefundStatus = false
		reservationOrderStatusText.value = res.data
	}

	return {
		orderStatusText,
		getOrderStatusText,
		orderRefundStatusText,
		getOrderRefundStatusText,
		orderCancelText,
		getOrderCancelText,
		reservationOrderStatusText,
		getReservationOrderStatusText
	}
})